<!--
* description: 修改关键信息
* author: dxuem
* createdDate: 2019-10-21
-->
<template>
  <section class="editChangeOwnerAudit">
    <el-dialog v-dialogDrag
      :close-on-click-modal="false"
      title="修改关键信息"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      @close="sendCode"
      width="900px"
    >
      <dialogHeader
        slot="title"
        :title="'修改关键信息'"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <div class="filter-container filter-title-crm">修改关键信息明细</div>
      <div class="filter-container-crm filter-params-crm">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents1.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :dateOptionsType="comp.dateOptionsType"
            :inputType="comp.type"
            :isMul="comp.isMul"
          ></component>
        </el-row>
      </div>
      <div class="filter-container-crm filter-title-crm">原信息</div>
      <div class="filter-container-crm filter-params-crm">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents2.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :dateOptionsType="comp.dateOptionsType"
            :inputType="comp.type"
            :isMul="comp.isMul"
          ></component>
        </el-row>
      </div>
      <div class="filter-container-crm filter-title-crm">新信息</div>
      <div class="filter-container-crm filter-params-crm">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents3.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="newformField[comp.codeField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :dateOptionsType="comp.dateOptionsType"
            :inputType="comp.type"
            :isMul="comp.isMul"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";
import { crmApis } from "@/api/apiList/crm";
import { requestAPI } from "@/api/commonRequest";
export default {
  // 组件混入对象
  mixins: [formMixins],
    components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: crmApis.createdOneIdMutationUpdateKeyValue, //关键信息修改
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.save(),
          text: "提交"
        }
        // {compKey: 'btnKey2', type: '', size: 'small', clickEvent: () => this.reset(), text: '重置'},
      ],
      // 动态组件-查询条件
      tableComponents1: [
        {
          compKey: "compKey1",
          labelName: "信息核实途径",
          codeField: "verifywayCode",
          // textField: "custName",
          isRequire: false,
          isMust: true,
          lookuptype: crmApis.mdmBaseVerifywayQueryFindAll,
          component: () => import("@/components/crm/lookupValue/apiDropList")
        },
        {
          compKey: "compKey2",
          labelName: "客户名称",
          codeField: "custName",
          isRequire: false,
          isMust: true,
          disabled: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        }
      ],
      tableComponents2: [
        {
          compKey: "compKey3",
          labelName: "电话",
          codeField: "phone",
          isMul: false,
          disabled: true,
          isMust: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        },
        {
          compKey: "compKey4",
          labelName: "证件类型",
          codeField: "credTypeCode",
          lookuptype: "DB0037",
          isRequire: false,
          isMust: true,
          disabled: true,
          component: () => import("@/components/crm/lookupValue/lookupvalue")
        },
        {
          compKey: "compKey5",
          labelName: "证件号码",
          codeField: "credNo",
          isRequire: false,
          isMust: true,
          disabled: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        },
        {
          compKey: "compKey6",
          labelName: "详细地址",
          codeField: "addrStreet",
          isRequire: false,
          isMust: true,
          disabled: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        }
      ],
      tableComponents3: [
        {
          compKey: "compKey7",
          labelName: "电话",
          codeField: "phone",
          isMul: false,
          isRequire: true,
          isMust: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        },
        {
          compKey: "compKey8",
          labelName: "证件类型",
          codeField: "credTypeCode",
          lookuptype: "DB0037",
          isRequire: true,
          isMust: true,
          component: () => import("@/components/crm/lookupValue/lookupvalue")
        },
        {
          compKey: "compKey9",
          labelName: "证件号码",
          codeField: "credNo",
          isRequire: true,
          isMust: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        },
        {
          compKey: "compKey10",
          labelName: "省份",
          codeField: "provinceId",
          textField: "addrProvince",
          isRequire: true,
          isMust: true,
          isMul: false,
          component: () => import("@/components/crm/Select/Common/mix_Province")
        },
        {
          compKey: "compKey11",
          labelName: "城市",
          codeField: "cityId",
          textField: "addrCity",
          isRequire: true,
          isMust: true,
          isMul: false,
          component: () => import("@/components/crm/Select/Common/mix_City")
        },
        {
          compKey: "compKey12",
          labelName: "区县",
          codeField: "countyId",
          textField: "addrCounty",
          isRequire: true,
          isMust: true,
          isMul: false,
          component: () => import("@/components/crm/Select/Common/mix_District")
        },
        {
          compKey: "compKey13",
          labelName: "详细地址",
          codeField: "addrStreet",
          isRequire: true,
          isMust: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        }
      ],
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        custName: "",
        phone: "",
        credTypeCode: "",
        credNo: "",
        provinceId: "",
        cityId: "",
        countyId: "",
        dlrCustNo: ""
      },
      newformField: {
        phone: "",
        credTypeCode: "",
        credNo: "",
        provinceId: "",
        cityId: "",
        countyId: "",
        dlrCustNo: "",
        custName: ""
      }
    };
  },
  methods: {
    init() {
      debugger;
      let params = this.$parent.$parent.formField;
      for (let key in this.formField) {
        if (params.hasOwnProperty(key)) {
          this.formField[key] = params[key];
        }
      }
    },
    save() {
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        this.saveForm();
      }
    },
    saveForm() {
      debugger;
      //保存表单
      this.newformField.dlrCustNo = this.formField.dlrCustNo;
      this.newformField.custName = this.formField.custName;
      let that = this;
      let queryObj = {
        type: "mutation",
        apiConfig: crmApis.createdOneIdMutationUpdateKeyValue, //关键信息修改
        variables: {
          dataInfo: {
            custInfo: this.newformField
          }
        }
      };
      var paramD = that.$getParams(queryObj);
      requestAPI(paramD).then(response => {
        if (
          response.data[queryObj.apiConfig.ServiceCode].result == "1"
          // &&response.data[queryObj.apiConfig.ServiceCode].rows != ""
        ) {
          that.$crmcf.showMessages(that, "success", "保存成功！");
        } else {
          that.$crmcf.showMessages(
            that,
            "error",
            response.data[queryObj.apiConfig.ServiceCode].msg
          );
        }
      });
    }
  }
};
</script>
